package com.java.al.swing;

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.HashMap;
import java.util.Map;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

public class TextArea extends JFrame {
	private JButton
		b = new JButton("Add Data"),
		c = new JButton("Clear Data");
	private JTextArea t = new JTextArea(20,40);
	private Map<String,String> m = new HashMap<String,String> ();
	public TextArea(){
		m.putAll(Countries.capitals());
		b.addActionListener( new ActionListener(){
			public void actionPerformed(ActionEvent e){
//				System.out.println("bbbbbbbbbbbbbbbb");
				for(Map.Entry me : m.entrySet()){
//					System.out.println(me);
					t.append(me.getKey() + "\t:\t" + me.getValue() + "\n");
				}
			}
		});
		c.addActionListener( new ActionListener(){
			public void actionPerformed( ActionEvent e){
//				System.out.println("cccccccccccc");
				t.setText("");
			}
		});
		setLayout( new FlowLayout());
		add( new JScrollPane( t ));//在JTextArea被添加到JFrame之前 使用JSrollPane包装.获得滚动功能;
		add(b);
		add(c);
	}
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		SwingConsole.run( new TextArea(), 475, 425);
	}

}
